package com.wisezone.workflow.web;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzFunAnnotation;
import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.utils.ConstantUtils;
import com.wisezone.workflow.bean.WfDataDictionary;
import com.wisezone.workflow.bean.form.WfDataDictionaryForm;
import com.wisezone.workflow.bean.search.WfDataDictionarySearch;
import com.wisezone.workflow.exception.WfWebException;

/**
 * 流程数据字典控制类 2010-08-26
 * @author shan
 *
 */
@WzWebAnnotation(moduleName="dataDict")
public class WfDataDictController extends WfWorkFlowController<WfDataDictionary, 
WfDataDictionarySearch,
WfDataDictionaryForm> {

	
	
	private List<WfDataDictionary> parentDataDictList;
	

	 /**
	  * 获得列表
	  * @return
	  * @throws Exception
	  */
	 public String list() throws WfWebException{
		 
		 searchEntity = getSearchEntity(true);
		 pagination = flowEngine.getWfDataDictionaryDao().listFormByPage(searchEntity);
		 return LIST;
	 }

	 
	 /**
	  * 进入新增
	  * @return
	  * @throws Exception
	  */
	 public String enterNew() throws WfWebException{
		
		 if(id != null){
			 entity = flowEngine.getWfDataDictionaryDao().load(id);
			 entity.setId(null);
		 }
		 return NEW_EDIT;
	 }
	 
	 /**
	  * 进入修改
	  * @return
	  * @throws Exception
	  */
	 public String enterEdit() throws WfWebException{
		 
		 entity = flowEngine.getWfDataDictionaryDao().load(id);
		 return NEW_EDIT;
	 }
	 
	 /**
	  * 进入查看
	  * @return
	  * @throws Exception
	  */
	 public String enterView() throws WfWebException{
		 
		 entity = flowEngine.getWfDataDictionaryDao().load(id);
		 return VIEW;
	 }
	 
	 /**
	  * 保存
	  * @return
	  * @throws Exception
	  */
	 public String save() throws WfWebException{

		 if(id != null){
			 return update();
		 }
		 entity = getEntity();
		 this.flowEngine.getWfDataDictionaryDao().save(entity);
		 return getRedirect(LIST);
	 }
	 
	 /**
	  * 修改
	  * @return
	  * @throws Exception
	  */
	 public String update() throws WfWebException{
		 
		 entity = getEntity();
		 this.flowEngine.getWfDataDictionaryDao().save(entity);
		 return getRedirect(LIST);
	 }
	 
	 /**
	  * 删除
	  * @return
	  * @throws Exception
	  */
	 public String delete() throws WfWebException{
		 
		 Collection<Serializable> idList = getIdList();
		 if(idList != null){
			flowEngine.getWfDataDictionaryDao().deleteAllById(idList);
		 }
		 return getRedirect(LIST);
	 }
	 
	 
	
    /**
     * 获得父类列表
     * @return
     */
	public List<WfDataDictionary> getParentDataDictList() {
		
		WfDataDictionarySearch searchEntity = new WfDataDictionarySearch();
		searchEntity.addSqlClause("parent_id < 1");
		parentDataDictList = this.getDataDictList(searchEntity);
		return parentDataDictList;
	}

	 
	
}
